package study.chapter03.designmodel.singleton;

//单例模式-懒汉式
public class SingletonDemo3 {
    public static void main(String[] args) {
        Singleton3 singleton = Singleton3.getInstance();
        singleton.hello();

    }

}

class Singleton3{
    private static Singleton3 instance;
    private Singleton3(){}

    public synchronized static Singleton3 getInstance() {
        if (instance == null){
            instance = new Singleton3();
        }
        return instance;
    }

    public void hello(){
        System.out.println("Hello World! ——单例模式-懒汉式");
    }
}

